﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      Show Category Province 
// Modify By:      Leo Ren (leoren@wicresoft.com)
// Modify Date:    2011-1-28
//------------------------------------------------------------------------------

namespace BEGDC.CC.Web.UserControls.CR
{
    using System;
    using System.Collections;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Web;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using BEGDC.CC.BL.CCFlow.CR;
    using BEGDC.CC.BL.Common;
    using BEGDC.CC.BL.Common.Query;
    using BEGDC.CC.BL.UserManagement;
    using BEGDC.CC.BL.Workflow;
    using BEGDC.CC.Entity;
    using BEGDC.CC.Web.UserControls;
    using BEGDC.Utility.Castle;

    /// <summary>
    ///		Summary description for NormalCtrl
    /// </summary>
    public class NormalCtrl : System.Web.UI.UserControl
    {
        private const string OtherAccounts = "Others";

        protected System.Web.UI.HtmlControls.HtmlTableRow trMeetingNeeds;
        protected System.Web.UI.WebControls.DataGrid dgASBLeaders;
        protected System.Web.UI.WebControls.Label lblMeetingNeeds;
        protected System.Web.UI.WebControls.Label lblOtherMeetingNeeds;
        protected System.Web.UI.WebControls.CheckBoxList cbMeetingNeeds;
        protected System.Web.UI.WebControls.TextBox tbOtherMeetingNeeds;
        protected System.Web.UI.HtmlControls.HtmlInputHidden positionflag;

        #region Variables
        protected System.Web.UI.WebControls.Label lbLegalEntityReadOnly;
        //protected System.Web.UI.WebControls.TextBox Ctl_ApplicantName;
        //protected System.Web.UI.WebControls.TextBox Ctl_Telephone;
        // protected System.Web.UI.WebControls.TextBox Ctl_Cellphone;
        protected System.Web.UI.WebControls.TextBox Ctl_Country;
        protected System.Web.UI.WebControls.TextBox Ctl_Company;
        protected System.Web.UI.WebControls.DataGrid DG_CustomerList;
        protected System.Web.UI.WebControls.TextBox Ctl_ArrivalDate;
        protected System.Web.UI.WebControls.TextBox Ctl_LeaveDate;
        protected System.Web.UI.WebControls.DataGrid DG_AccompanyingStaff;
        protected System.Web.UI.WebControls.DropDownList Dp_MeetingRoom;
        protected System.Web.UI.WebControls.TextBox Ctl_HotelDateFrom;
        protected System.Web.UI.WebControls.TextBox Ctl_HotelDateTo;
        protected System.Web.UI.WebControls.DropDownList Dp_RentedCar;
        protected System.Web.UI.WebControls.TextBox Ctl_ArrivalFlightNo;
        protected System.Web.UI.WebControls.TextBox ArrivalTime;
        protected System.Web.UI.WebControls.TextBox Ctl_LeaveFlightNo;
        protected System.Web.UI.WebControls.TextBox LeaveTime;
        //protected System.Web.UI.WebControls.Label tx_Applicant;
        //protected System.Web.UI.WebControls.Label tx_Telephone;
        //protected System.Web.UI.WebControls.Label tx_Cellphone;
        protected System.Web.UI.WebControls.Label tx_Country;
        protected System.Web.UI.WebControls.Label tx_Company;
        protected System.Web.UI.WebControls.Label Dt_ArrivalDate;
        protected System.Web.UI.WebControls.Label Dt_LeaveDate;
        protected System.Web.UI.WebControls.Label tx_MeetingRoom;
        protected System.Web.UI.WebControls.Label tx_RentedCar;
        protected System.Web.UI.WebControls.Label tx_ArrivalFightNo;
        protected System.Web.UI.WebControls.Label tx_ArrivalAirport;
        protected System.Web.UI.WebControls.Label tx_ArrivalTime;
        protected System.Web.UI.WebControls.Label tx_LeaveFightNo;
        protected System.Web.UI.WebControls.Label tx_LeaveAirport;
        protected System.Web.UI.WebControls.Label tx_LeaveTime;
        protected System.Web.UI.WebControls.Label Dt_HotelFromDate;
        protected System.Web.UI.WebControls.Label Dt_HotelToDate;
        protected System.Web.UI.WebControls.CheckBoxList CBL_VisitingSites;
        protected System.Web.UI.WebControls.DataGrid DG_Hotel;
        protected System.Web.UI.WebControls.Button CustomerPaneImg;
        protected System.Web.UI.WebControls.Button AccompanyingPaneImg;
        protected System.Web.UI.WebControls.DataGrid DG_CompanyCar;
        protected System.Web.UI.WebControls.DataGrid DG_LeaseCar;
        protected System.Web.UI.WebControls.RadioButtonList RBL_Entertainment;
        protected System.Web.UI.WebControls.TextBox Ctl_EntertainmentContent;
        protected System.Web.UI.WebControls.RadioButtonList RBL_Gift;
        protected System.Web.UI.WebControls.TextBox Ctl_GiftContent;
        protected System.Web.UI.WebControls.Label tx_EntertainmentContent;
        protected System.Web.UI.WebControls.Label tx_GiftContent;
        protected System.Web.UI.WebControls.RadioButtonList RBL_Meal;
        protected System.Web.UI.WebControls.TextBox Ctl_MealContent;
        protected System.Web.UI.WebControls.Label tx_MealContent;
        protected System.Web.UI.WebControls.Button HotelBookingImg;
        protected System.Web.UI.WebControls.Button CompanyCarImg;
        protected System.Web.UI.WebControls.Button LeaseCarImg;
        protected System.Web.UI.HtmlControls.HtmlGenericControl ArrivalDateSpan;
        protected System.Web.UI.HtmlControls.HtmlGenericControl LeaveDateSpan;
        protected System.Web.UI.HtmlControls.HtmlGenericControl HotelDateFromSpan;
        protected System.Web.UI.HtmlControls.HtmlGenericControl HotelDateToSpan;
        protected System.Web.UI.HtmlControls.HtmlGenericControl ArrivalTimeSpan;
        protected System.Web.UI.HtmlControls.HtmlGenericControl LeaveTimeSpan;
        protected System.Web.UI.WebControls.DropDownList Dp_Department;
        private BEGDC.CC.Entity.Application _Application = null;
        protected System.Web.UI.WebControls.Label tx_AllDepts;
        protected System.Web.UI.WebControls.Label tx_Account;
        protected System.Web.UI.HtmlControls.HtmlTableRow TR_Meal;
        protected System.Web.UI.WebControls.TextBox Ctl_ArrivalAirport;
        protected System.Web.UI.WebControls.TextBox Ctl_LeaveAirport;
        protected System.Web.UI.WebControls.Label Lb_CISWarning;
        protected System.Web.UI.WebControls.TextBox Ctl_Routing;
        protected System.Web.UI.WebControls.Label Lb_Routing;
        protected System.Web.UI.HtmlControls.HtmlTableRow Tr1;
        protected System.Web.UI.HtmlControls.HtmlTableRow EntertainmentPane1;
        protected System.Web.UI.HtmlControls.HtmlTableRow EntertainmentPane;
        protected System.Web.UI.WebControls.DropDownList Dp_Account;
        protected System.Web.UI.WebControls.TextBox tbDp_Account;
        protected System.Web.UI.HtmlControls.HtmlTableRow TR_Account;
        //protected System.Web.UI.WebControls.DropDownList ddlLegalEntity;
        //protected System.Web.UI.WebControls.Label lblLegalEntity;
        protected System.Web.UI.WebControls.Label lbSummaryReadOnly;
        protected System.Web.UI.HtmlControls.HtmlTableRow TR_KnowledgeTitle;
        protected System.Web.UI.HtmlControls.HtmlTableRow TR_Knowledge;
        //protected System.Web.UI.WebControls.CheckBoxList CBL_ASBLeader;
        protected System.Web.UI.HtmlControls.HtmlTable tbASBLeadership;

        private bool _isKnowledgeVisible = false;
        protected System.Web.UI.WebControls.Label tx_NumberOfPerson;
        protected System.Web.UI.WebControls.TextBox Ctl_LogisticComment;
        protected System.Web.UI.WebControls.Label lbLogisticComment;
        protected System.Web.UI.WebControls.TextBox Ctl_HotelComment;
        protected System.Web.UI.WebControls.Label lbhotelcomment;
        protected System.Web.UI.WebControls.CheckBox checkbox1;
        //protected System.Web.UI.HtmlControls.HtmlTableRow Tr2;
        protected System.Web.UI.WebControls.DropDownList Dp_CostCenter;
        //protected System.Web.UI.WebControls.Label lblCluster;
        protected System.Web.UI.WebControls.TextBox lblCluster;
        //protected System.Web.UI.WebControls.TextBox tbExpenditureAccount;
        //protected System.Web.UI.WebControls.TextBox tbCostCenterRemarks;
        protected ASB.CC.Web.UserControls.RequesterInfoControl RequesterInfoControl;
        private bool _isReadOnly = true;
        #endregion

        #region Properties
        public bool KnowledgeVisible
        {
            set
            {
                _isKnowledgeVisible = value;
            }
            get
            {
                return _isKnowledgeVisible;
            }
        }
        public bool isReadOnly
        {
            set
            {
                _isReadOnly = value;
            }
            get
            {
                return _isReadOnly;
            }
        }
        public BEGDC.CC.Entity.Application App
        {
            set
            {
                _Application = value;
            }
            get
            {
                return _Application;
            }
        }
        protected DateTime RequestDate
        {
            get
            {
                if (this.ViewState["RequestDate"] == null)
                    return System.DateTime.Now;
                return (DateTime)this.ViewState["RequestDate"];
            }
            set { this.ViewState["RequestDate"] = value; }
        }
        public string Dp_Dept_Value
        {
            get
            {
                return this.Dp_Department.SelectedItem.Value.ToString();
            }
        }
        public string Dp_CAT_Value
        {
            get
            {
                return this.Dp_Account.SelectedItem.Value.ToString();
            }
        }

        public int CustomerNum
        {
            get
            {
                if (this.DG_CustomerList != null)
                    return this.DG_CustomerList.Items.Count;
                else
                    return 0;
            }
        }

        public int AccompanyNum
        {
            get
            {
                if (this.DG_AccompanyingStaff != null)
                    return this.DG_AccompanyingStaff.Items.Count;
                else
                    return 0;
            }
        }

        public int HotelNum
        {
            get
            {
                if (this.DG_Hotel != null)
                    return this.DG_Hotel.Items.Count;
                else
                    return 0;
            }
        }

        public string RequestDateFrom
        {
            get
            {
                return this.Ctl_ArrivalDate.Text;
            }
        }
        public string RequestDateTo
        {
            get
            {
                return this.Ctl_LeaveDate.Text;
            }
        }

        public System.Data.DataTable CustomerDataTable
        {
            get
            {
                if (this.DG_CustomerList.DataSource != null)
                    return (DataTable)this.DG_CustomerList.DataSource;
                else
                    return null;
            }
        }

        public System.Data.DataTable ALAttendeeDataTable
        {
            get
            {
                if (this.DG_AccompanyingStaff.DataSource != null)
                    return (DataTable)this.DG_AccompanyingStaff.DataSource;
                else
                    return null;
            }
        }

        public System.Data.DataTable HotelDataTable
        {
            get
            {
                if (this.DG_Hotel.DataSource != null)
                    return (DataTable)this.DG_Hotel.DataSource;
                else
                    return null;
            }
        }

        public System.Data.DataTable CompanyCarDataTable
        {
            get
            {
                if (this.DG_CompanyCar.DataSource != null)
                    return (DataTable)this.DG_CompanyCar.DataSource;
                else
                    return null;
            }
        }

        public System.Data.DataTable LeaseCarDataTable
        {
            get
            {
                if (this.DG_LeaseCar.DataSource != null)
                    return (DataTable)this.DG_LeaseCar.DataSource;
                else
                    return null;
            }
        }

        public string Dp_CostCenter_Value
        {
            get
            {
                return this.Dp_CostCenter.SelectedItem.Value.ToString();
            }
        }

        #endregion

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!this.IsPostBack)
            {
                checkbox1.Attributes.Add("onclick", "javascript:checkBoxDisable();");

                this.TR_Knowledge.Visible = false;
                this.TR_KnowledgeTitle.Visible = false;
                this.tbASBLeadership.Visible = false;
                //this.CBL_ASBLeader.Visible = false;
                this.dgASBLeaders.Visible = false;

                Session[SessionFlag.AccompanySessionEZ] = null;
                Session[SessionFlag.CustomerSessionEZ] = null;
                Session[SessionFlag.ContractInfo] = null;
                Session[SessionFlag.CostCenter] = null;
                Session[SessionFlag.AccompanySession] = null;
                Session[SessionFlag.CustomerSession] = null;
                Session[SessionFlag.MeetingMinutesAttendee] = null;

                InitForm();

                //positionflag
                if (!string.IsNullOrEmpty(Request.QueryString["pf"]))
                {
                    int position;
                    if (Int32.TryParse(Request.QueryString["pf"], out position))
                        positionflag.Value = position.ToString();
                }

                #region Radio List OnClick
                this.RBL_Meal.Attributes["onclick"] = "javascript:ShowRBL_MealPane();";
                this.RBL_Entertainment.Attributes["onclick"] = "javascript:ShowEntertainmentNeedPane();";
                this.RBL_Gift.Attributes["onclick"] = "javascript:ShowGiftNeedPane();";
                #endregion

                //RegisterClientScripts();
            }
            else
            {
                #region RELOAD DATAGRID
                DataTable CustomerDataTable = null;
                object SessCustomerAttendee = Session[SessionFlag.CustomerSession];
                if (SessCustomerAttendee != null)
                {
                    CustomerDataTable = (DataTable)SessCustomerAttendee;
                    this.DG_CustomerList.DataSource = CustomerDataTable;
                    this.DG_CustomerList.DataBind();
                    if (this.DG_CustomerList != null && this.DG_CustomerList.Items.Count > 0)
                    {
                        this.tx_NumberOfPerson.Text = this.DG_CustomerList.Items.Count.ToString();
                    }
                    else
                    {
                        this.tx_NumberOfPerson.Text = "0";
                    }
                }
                if (CheckCISCustomer())
                {
                    this.Lb_CISWarning.Visible = true;
                }
                else
                {
                    this.Lb_CISWarning.Visible = false;
                }
                DataTable AlcatelAttendeeTable = null;
                object SessAlcatelAttendee = Session[SessionFlag.AccompanySession];
                if (SessAlcatelAttendee != null)
                {
                    DG_AccompanyingStaff.DataSource = null;
                    AlcatelAttendeeTable = (DataTable)SessAlcatelAttendee;
                    this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataBind();
                }
                DataTable HotelDataTable = null;
                object SessHotelBooking = Session[SessionFlag.HotelSession];
                if (SessHotelBooking != null)
                {
                    HotelDataTable = (DataTable)SessHotelBooking;
                    this.DG_Hotel.DataSource = HotelDataTable;
                    this.DG_Hotel.DataBind();
                }
                DataTable CompanyCarDataTable = null;
                object SessCompanyCarBooking = Session[SessionFlag.CompanyCarSession];
                if (SessCompanyCarBooking != null)
                {
                    CompanyCarDataTable = (DataTable)SessCompanyCarBooking;
                    this.DG_CompanyCar.DataSource = CompanyCarDataTable;
                    this.DG_CompanyCar.DataBind();
                    //this.Lb_TotalPriceForCompanyCar.Text = CaculateTotalPriceForLeaseCar(CompanyCarDataTable);
                }
                DataTable LeaseCarDataTable = null;
                object SessLeaseCarBooking = Session[SessionFlag.LeaseCarSession];
                if (SessLeaseCarBooking != null)
                {
                    LeaseCarDataTable = (DataTable)SessLeaseCarBooking;
                    this.DG_LeaseCar.DataSource = LeaseCarDataTable;
                    this.DG_LeaseCar.DataBind();
                    //this.Lb_TotalPriceForLeaseCar.Text = CaculateTotalPriceForLeaseCar(LeaseCarDataTable);
                }
                #endregion
            }
            //			Page.SmartNavigation = true;
            ShowBlock();
        }

        #region RegisterClientScripts
        //		public void RegisterClientScripts()
        //		{
        //			StringBuilder sb = new StringBuilder();
        //			if(Page.IsPostBack)
        //			{
        //				//Post back get init value from control.
        //				sb.Append("<script language=\"javascript\">\n");
        //				sb.Append("var _MealReservation;\n");
        //				sb.Append("var _EntertainmentNeed;\n");
        //				sb.Append("var _GiftNeed;\n");
        //
        //				sb.Append("_MealReservation = ");
        //				sb.Append(this.RBL_Meal.SelectedValue == "1" ? "true":"false");
        //				sb.Append(";\n");
        //				sb.Append("_EntertainmentNeed = ");
        //				sb.Append(this.RBL_Entertainment.SelectedValue =="1" ? "true":"false");
        //				sb.Append(";\n");
        //				sb.Append("_GiftNeed = ");
        //				sb.Append(this.RBL_Gift.SelectedValue=="1" ? "true":"false");
        //				sb.Append(";\n");
        //				sb.Append("</script>");
        //			}
        //			else
        //			{
        //				sb.Append("<script language=\"javascript\">\n");
        //				sb.Append("var _MealReservation;\n");
        //				sb.Append("var _EntertainmentNeed;\n");
        //				sb.Append("var _GiftNeed;\n");
        //
        //				sb.Append("_MealReservation = ");
        //				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsMealReservation ? "true":"false"));
        //				sb.Append(";\n");
        //				sb.Append("_EntertainmentNeed = ");
        //				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedEntertainment ? "true":"false"));
        //				sb.Append(";\n");
        //				sb.Append("_GiftNeed = ");
        //				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedGift ? "true":"false"));
        //				sb.Append(";\n");
        //				sb.Append("</script>");
        //				
        //			}
        //
        //			if(!Page.IsClientScriptBlockRegistered("EZCtrlForCO"))
        //			{
        //				Page.RegisterClientScriptBlock("EZCtrlForCO",sb.ToString());
        //			}
        //			sb = new StringBuilder();
        //			if(!Page.IsStartupScriptRegistered("EZCtrlForCO_Startup"))
        //			{
        //				sb.Append( "<script language=\"javascript\">\n");
        //				sb.Append( "DisplayRBL_MealPane(_MealReservation);\n");
        //				sb.Append( "DisplayEntertainmentNeedPane(_EntertainmentNeed);\n");
        //				sb.Append( "DisplayGiftNeedPane(_GiftNeed);\n");
        //				sb.Append("</script>\n");
        //
        //				Page.RegisterStartupScript("EZCtrlForCO_Startup",sb.ToString());
        //			}
        //		}
        #endregion

        #region ShowBlock
        private void ShowBlock()
        {
            StringBuilder sb = new StringBuilder();
            if (!Page.IsStartupScriptRegistered("Normal_Startup"))
            {
                sb.Append("<script language=\"javascript\">\n");
                if (this.isReadOnly)
                {
                    sb.Append("DisplayRBL_MealPane(" + this.RBL_Meal.SelectedValue + ");\n");
                    sb.Append("DisplayEntertainmentNeedPane(" + this.RBL_Entertainment.SelectedValue + ");\n");
                    sb.Append("DisplayGiftNeedPane(" + this.RBL_Gift.SelectedValue + ");\n");
                }
                else
                {
                    sb.Append("ShowRBL_MealPane();\n");
                    sb.Append("ShowEntertainmentNeedPane();\n");
                    sb.Append("ShowGiftNeedPane();\n");
                }
                sb.Append("</script>\n");

                Page.RegisterStartupScript("Normal_Startup", sb.ToString());
            }
        }
        #endregion

        #region INITFORM
        private void InitForm()
        {
            this.ControlsDisplay(this.isReadOnly);
            InitFormData();

            if (this.App != null && this.isReadOnly)
            {
                LoadReadOnlyForm();
            }
            else
            {
                LoadEditForm();
            }

            this.RequesterInfoControl.isReadOnly = this.isReadOnly;
        }
        #endregion

        #region INIT FORM DATA
        private void InitFormData()
        {
            IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;

            WebUtility.BuildDropDown(this.Dp_MeetingRoom, BEGDC.CC.BL.Common.DicType.MeetingRoom, false, false);
            //WebUtility.BuildCheckBoxList(this.CBL_VisitingSites, BEGDC.CC.BL.Common.DicType.ASB_Visiting_Locations);


            //WebUtility.BuildDropDown(Dp_CostCenter, BEGDC.CC.BL.Common.DicType.CostCenter, true, false);

            //this.ddlLegalEntity.DataSource = queryService.GetAllLegalEntity();
            //this.ddlLegalEntity.DataTextField = "LegalEntityName";
            //this.ddlLegalEntity.DataValueField = "LegalEntityID";
            //this.ddlLegalEntity.DataBind();
        }
        #endregion

        #region LOAD READONLY FORM
        private void LoadReadOnlyForm()
        {
            ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;

            Employee CurrentUser = this.GetUser(HttpContext.Current.User.Identity.Name);

            //APPLICATION INFORMATION
            if (this.App != null)
            {
                if (this.App.IsTransition) return;

                //this.tx_Applicant.Text = this.App.RequesterNameEN;
                //this.tx_Telephone.Text = this.App.RequesterOfficeTel;
                //this.tx_Cellphone.Text = this.App.RequesterMobile;
                if (this.App.RequestDate != null)
                    this.RequestDate = (DateTime)this.App.RequestDate;

                //this.tx_AllDepts.Text = this.App.AllDept;
                this.tx_AllDepts.Text = this.App.CATBranch;
                this.lblCluster.Text = this.App.Others;
                this.tx_Account.Text = this.App.Account;

                if (this.App.RequestedDateFrom != null && this.App.RequestedDateFrom != "")
                {
                    this.Dt_ArrivalDate.Text = ((DateTime)this.App.RequestedDateFrom).ToString("MM/dd/yyyy");
                }
                if (this.App.RequestedDateTo != null && this.App.RequestedDateTo != "")
                {
                    this.Dt_LeaveDate.Text = ((DateTime)this.App.RequestedDateTo).ToString("MM/dd/yyyy");
                }
                //if (this.App.LegalEntity != null)
                //{
                //    this.lblLegalEntity.Text = this.App.LegalEntity.LegalEntityName;
                //}
                if (this.KnowledgeVisible)
                {
                    this.TR_Knowledge.Visible = true;
                    this.TR_KnowledgeTitle.Visible = true;

                    this.tbASBLeadership.Visible = true;
                    //this.CBL_ASBLeader.Visible = true;
                    //this.CBL_ASBLeader.Enabled = false;
                    this.dgASBLeaders.Visible = true;
                    this.SetSelectedASBLeaders();
                    this.lbSummaryReadOnly.Text = this.App.Summary;
                }
                //this.App.CostCenterCode != null
                if (this.App.CostCenterName != "")
                {
                    //this.Dp_CostCenter.SelectedValue = this.App.CostCenterCode.Id.ToString();
                    //if (!string.IsNullOrEmpty(App.AllDept))
                    //{
                    //    IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                    //    Department dept = query.GetDepartmentByCode(App.AllDept);
                    //    this.BindCostCenterList();
                    //}
                    //this.BindCostCenterList();
                    this.Dp_CostCenter.Items.Insert(0, new ListItem(this.App.CostCenterName, String.Empty));
                    //this.tbCostCenterRemarks.Text = this.App.CostCenterName;
                    //this.tbCostCenterRemarks.Text = this.App.ReasonOfLocation;
                    //this.tbExpenditureAccount.Text = this.App.OtherCountry;

                    this.Dp_CostCenter.Enabled = false;
                    //this.tbCostCenterRemarks.Enabled = false;
                    //this.tbCostCenterRemarks.Enabled = false;
                    //this.tbExpenditureAccount.Enabled = false;
                }

            }

            //CUSTOMER INFORMATION
            //CUSTOMER ATTENDEE
            //LOAD CUSTOMER ATTENDEE LIST
            BEGDC.CC.Entity.CustomerInfo customer = null;
            if (this.App != null)
            {
                customer = CRService.GetCustomerInfo(this.App.Id);
            }
            if (customer != null)
            {
                this.tx_Country.Text = customer.Country;
                this.tx_Company.Text = customer.Company;
                //this.tx_NumberOfPerson.Text = customer.NumberOfPerson;

                DataTable CustomerDataTable = CRService.GetCustomerAttendeeList(customer.Id);

                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    this.DG_CustomerList.DataSource = CustomerDataTable;
                    this.DG_CustomerList.DataBind();
                    this.DG_CustomerList.Columns[9].Visible = false;
                    if (CheckCISCustomer())
                    {
                        this.Lb_CISWarning.Visible = true;
                    }
                    else
                    {
                        this.Lb_CISWarning.Visible = false;
                    }
                }

                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    this.tx_NumberOfPerson.Text = CustomerDataTable.Rows.Count.ToString();
                }
                else
                {
                    this.tx_NumberOfPerson.Text = "0";
                }
            }

            //READONLY ASB ACCOMPANYING INFORMATION
            DataTable AlcatelAttendeeTable = CRService.GetAccompanyingAttendeeList(this.App.Id);
            if (AlcatelAttendeeTable != null && AlcatelAttendeeTable.Rows.Count > 0)
            {
                this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                this.DG_AccompanyingStaff.DataBind();
            }
            this.DG_AccompanyingStaff.Columns[4].Visible = false;

            //Visiting Sites
            if (this.App != null)
            {
                IList AppVisitingSites = CRService.GetVisitingSites(this.App.Id);
                if (AppVisitingSites != null && AppVisitingSites.Count > 0)
                {
                    BEGDC.CC.Entity.AppVisitingSite AppVS = null;
                    System.Web.UI.WebControls.ListItem item = null;
                    for (int i = 0; i < AppVisitingSites.Count; i++)
                    {
                        AppVS = (BEGDC.CC.Entity.AppVisitingSite)AppVisitingSites[i];
                        item = this.CBL_VisitingSites.Items.FindByValue(AppVS.Site.Id.ToString());
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }
            }

            //LOGISTICAL INFOMATION
            BEGDC.CC.Entity.LogisticalInfo LogisticalInfo = null;
            if (this.App != null)
            {
                LogisticalInfo = CRService.GetLogisticalInfo(this.App.Id);
                //m_CachedLogist = LogisticalInfo;
            }
            if (LogisticalInfo != null)
            {
                this.lbhotelcomment.Text = LogisticalInfo.HotelComment;
                if (LogisticalInfo.MeetingRoom != null)
                {
                    this.tx_MeetingRoom.Text = LogisticalInfo.MeetingRoom.DicItemKey.ToString();
                }
                //if (this.tx_MeetingRoom.Text.Contains("Yes"))
                if (!string.IsNullOrEmpty(LogisticalInfo.MeetingNeeds))
                {
                    this.trMeetingNeeds.Visible = true;
                    this.lblMeetingNeeds.Text = LogisticalInfo.MeetingNeeds;
                    this.lblOtherMeetingNeeds.Text = LogisticalInfo.OtherMeetingNeeds;
                }

                if (LogisticalInfo.DateRequiredFrom != null && LogisticalInfo.DateRequiredFrom != "")
                {
                    this.Dt_HotelFromDate.Text = ((DateTime)LogisticalInfo.DateRequiredFrom).ToString("MM/dd/yyyy");
                }
                if (LogisticalInfo.DateRequiredTo != null && LogisticalInfo.DateRequiredTo != "")
                {
                    this.Dt_HotelToDate.Text = ((DateTime)LogisticalInfo.DateRequiredTo).ToString("MM/dd/yyyy");
                }
                InitRadioControl(this.RBL_Meal, LogisticalInfo.IsNeedCatering);
                this.tx_MealContent.Text = LogisticalInfo.CateringDescription;
                this.lbLogisticComment.Text = LogisticalInfo.Comment;

                this.tx_ArrivalFightNo.Text = LogisticalInfo.ArrivalFlightNo;
                this.tx_ArrivalAirport.Text = LogisticalInfo.ArrivalAirport;
                if (LogisticalInfo.ArrivalTime != null && LogisticalInfo.ArrivalTime != "")
                {
                    this.tx_ArrivalTime.Text = ((DateTime)LogisticalInfo.ArrivalTime).ToString("MM/dd/yyyy");
                }

                this.tx_LeaveFightNo.Text = LogisticalInfo.DepartureFlightNo;
                this.tx_LeaveAirport.Text = LogisticalInfo.DepartureAirport;
                if (LogisticalInfo.DepartureTime != null && LogisticalInfo.DepartureTime != "")
                {
                    this.tx_LeaveTime.Text = ((DateTime)LogisticalInfo.DepartureTime).ToString("MM/dd/yyyy");
                }
                this.Lb_Routing.Text = LogisticalInfo.Itinerary;

                InitRadioControl(this.RBL_Entertainment, LogisticalInfo.IsNeedEntertainment);
                this.tx_EntertainmentContent.Text = LogisticalInfo.EntertainmentPreference;

                InitRadioControl(this.RBL_Gift, LogisticalInfo.IsNeedGift);
                this.tx_GiftContent.Text = LogisticalInfo.GiftDetails;

                this.lbLogisticComment.Text = LogisticalInfo.Comment;
                this.checkbox1.Checked = LogisticalInfo.IsNormalBusiness;
                this.checkbox1.Enabled = false;

                //HOTEL PREFERENCE
                //LOAD HOTEL LIST
                DataTable HotelDataTable = CRService.GetHotelRoomBookingList(LogisticalInfo.Id, false);
                if (HotelDataTable != null && HotelDataTable.Rows.Count > 0)
                {
                    this.DG_Hotel.DataSource = HotelDataTable;
                    this.DG_Hotel.DataBind();
                }
                this.DG_Hotel.Columns[6].Visible = false;


                //COMPANY CAR
                //LOAD COMPANY CAR LIST
                DataTable CompanyCarDataTable = CRService.GetVehicleBookingList(LogisticalInfo.Id, BEGDC.CC.BL.Common.DicType.AlcatelCar);
                if (CompanyCarDataTable != null && CompanyCarDataTable.Rows.Count > 0)
                {
                    this.DG_CompanyCar.DataSource = CompanyCarDataTable;
                    this.DG_CompanyCar.DataBind();
                    //this.Lb_TotalPriceForCompanyCar.Text = CaculateTotalPriceForLeaseCar(CompanyCarDataTable);
                }
                this.DG_CompanyCar.Columns[4].Visible = false;

                //LEASE CAR
                //LOAD LEASE CAR LIST
                DataTable LeaseCarDataTable = CRService.GetVehicleBookingList(LogisticalInfo.Id, BEGDC.CC.BL.Common.DicType.LeaseCar);
                if (LeaseCarDataTable != null && LeaseCarDataTable.Rows.Count > 0)
                {
                    this.DG_LeaseCar.DataSource = LeaseCarDataTable;
                    this.DG_LeaseCar.DataBind();
                    //this.Lb_TotalPriceForLeaseCar.Text = CaculateTotalPriceForLeaseCar(LeaseCarDataTable);
                }
                this.DG_LeaseCar.Columns[4].Visible = false;
            }
        }
        #endregion

        #region LOAD EDIT FORM

        private void BuildDepartmentCATList()
        {
            //BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
            //IList DeptList = utility.BuildDicList(BEGDC.CC.BL.Common.DicType.BRANCH);

            //BEGDC.CC.BL.Common.Query.IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;
            //DataTable catTable = queryService.GetDeptByTypeName(BEGDC.CC.BL.Common.DicType.CAT);
            //DataTable branchTable = queryService.GetDeptByTypeName(BEGDC.CC.BL.Common.DicType.BRANCH);

            //DataRow[] rows = catTable.Select();
            //foreach (DataRow row in rows)
            //{
            //    branchTable.ImportRow(row);
            //}

            //this.Dp_Department.DataSource = branchTable;
            //this.Dp_Department.DataValueField = "DepartmentCode";
            //this.Dp_Department.DataTextField = "DepartmentCode";
            //this.Dp_Department.DataBind();

            //this.Dp_Department.Items.Insert(this.Dp_Department.Items.Count, new System.Web.UI.WebControls.ListItem("Other Department", "OTH"));
            ////this.Dp_Department.Items.Insert(0,new System.Web.UI.WebControls.ListItem("HQ","HQ"));

            //if (this.Dp_Department.Items.Count > 0)
            //{
            //    this.Dp_Department.Items[0].Selected = true;
            //}

            //init cat branch
            BEGDC.CC.BL.Common.Query.IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;

            DataTable categoryTable = queryService.GetPCATNameList(true);
            DataTable provinceTable = queryService.GetPCATNameList(false);
            foreach (DataRow row in categoryTable.Select())
            {
                provinceTable.ImportRow(row);
            }

            this.Dp_Department.DataSource = provinceTable.DefaultView;
            this.Dp_Department.DataTextField = "Name";
            this.Dp_Department.DataValueField = "Name";
            this.Dp_Department.DataBind();
            this.Dp_Department.Items.Insert(0, new ListItem("Please select", String.Empty));

            //Initialize Account Dropdown List
            DataTable accountTable = queryService.GetDicItemByTypeName(BEGDC.CC.BL.Common.DicType.ACCOUNT);
            this.Dp_Account.DataSource = accountTable.DefaultView;
            this.Dp_Account.DataValueField = "DicItemKey";
            this.Dp_Account.DataTextField = "Description";

            this.Dp_Account.DataBind();
            this.Dp_Account.Items.Insert(0, new ListItem("Please select", String.Empty));
            if (this.Dp_Account.Items.Count > 0)
            {
                this.Dp_Account.Items[0].Selected = true;
            }
            //this.Dp_CAT.DataSource = catTable;
            //this.Dp_CAT.DataValueField = "DepartmentCode";
            //this.Dp_CAT.DataTextField = "DepartmentCode";
            //this.Dp_CAT.DataBind();
        }

        private Employee GetUser(string name)
        {
            IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
            return userService.GetUser(name);
        }


        private void LoadEditForm()
        {
            ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
            BuildDepartmentCATList();

            Employee CurrentUser = this.GetUser(HttpContext.Current.User.Identity.Name);

            //Application Infomation
            if (this.App != null)
            {
                if (this.App.IsTransition) return;

                //this.Ctl_ApplicantName.Text = this.App.RequesterNameEN;
                //this.Ctl_Telephone.Text = this.App.RequesterOfficeTel;
                //this.Ctl_Cellphone.Text = this.App.RequesterMobile;
                if (this.App.RequestDate != null)
                    this.RequestDate = (DateTime)this.App.RequestDate;

                //this.Dp_Department.SelectedIndex = Dp_Department.Items.IndexOf(Dp_Department.Items.FindByValue(this.App.AllDept));
                this.Dp_Department.SelectedIndex = Dp_Department.Items.IndexOf(Dp_Department.Items.FindByValue(this.App.CATBranch));
                this.lblCluster.Text = this.App.Others;
                //this.lblCluster.CssClass = "Cluster_Block";
                //this.Dp_Account.SelectedIndex = this.Dp_Account.Items.IndexOf(Dp_Account.Items.FindByText(this.App.Account));
                if (this.App.Account != string.Empty)
                {
                    //this.Dp_Account.SelectedIndex = this.Dp_Account.Items.IndexOf(this.Dp_Account.Items.FindByText(this.App.Account));
                    if (this.Dp_Account.Items.FindByValue(this.App.Account) != null)
                    {
                        this.Dp_Account.SelectedIndex = this.Dp_Account.Items.IndexOf(this.Dp_Account.Items.FindByValue(this.App.Account));
                    }
                    else
                    {
                        this.Dp_Account.SelectedIndex = this.Dp_Account.Items.IndexOf(this.Dp_Account.Items.FindByValue(OtherAccounts));
                        this.tbDp_Account.Text = this.App.Account;
                    }
                }
                else
                {
                    this.TR_Account.Visible = false;
                }

                if (this.App.RequestedDateFrom != null && this.App.RequestedDateFrom != "")
                {
                    this.Ctl_ArrivalDate.Text = ((DateTime)this.App.RequestedDateFrom).ToString("MM/dd/yyyy");
                }
                if (this.App.RequestedDateTo != null && this.App.RequestedDateTo != "")
                {
                    this.Ctl_LeaveDate.Text = ((DateTime)this.App.RequestedDateTo).ToString("MM/dd/yyyy");
                }
                //if (this.App.LegalEntity != null)
                //{
                //    this.ddlLegalEntity.SelectedValue = this.App.LegalEntity.Id.ToString();
                //}
                //this.App.CostCenterCode != null
                if (!string.IsNullOrEmpty(this.App.CostCenterName))
                {
                    //this.Dp_CostCenter.SelectedValue = this.App.CostCenterCode.Id.ToString();
                    //if (!string.IsNullOrEmpty(App.AllDept))
                    //{
                    //    IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                    //    Department dept = query.GetDepartmentByCode(App.AllDept);
                    //    this.BindCostCenterList();
                    //}
                    this.BindCostCenterList();
                    this.Dp_CostCenter.Text = this.App.CostCenterName.Trim();
                    //this.tbExpenditureAccount.Text = this.App.OtherCountry;
                    //this.tbCostCenterRemarks.Text = this.App.ReasonOfLocation;
                }
            }
            //else
            //{
            //    this.Ctl_ApplicantName.Text = CurrentUser.NameEN;
            //}

            //Customer Infomation
            BEGDC.CC.Entity.CustomerInfo customer = null;
            if (this.App != null)
            {
                customer = CRService.GetCustomerInfo(this.App.Id);
            }
            if (customer != null)
            {
                this.Ctl_Country.Text = customer.Country;
                this.Ctl_Company.Text = customer.Company;
                //this.tx_NumberOfPerson.Text = customer.NumberOfPerson;
            }

            //Customer Attendee
            DataTable CustomerDataTable = null;
            object SessCustomerAttendee = Session[SessionFlag.CustomerSession];
            if (SessCustomerAttendee != null)
            {
                DG_CustomerList.DataSource = null;
                CustomerDataTable = (DataTable)SessCustomerAttendee;
                this.DG_CustomerList.DataSource = CustomerDataTable;
                this.DG_CustomerList.DataBind();

                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    this.tx_NumberOfPerson.Text = CustomerDataTable.Rows.Count.ToString();
                    if (CheckCISCustomer())
                    {
                        this.Lb_CISWarning.Visible = true;
                    }
                    else
                    {
                        this.Lb_CISWarning.Visible = false;
                    }
                }
                else
                {
                    this.tx_NumberOfPerson.Text = "0";
                }
            }
            else
            {
                if (customer != null)
                {
                    CustomerDataTable = CRService.GetCustomerAttendeeList(customer.Id);
                }
                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    Session[SessionFlag.CustomerSession] = CustomerDataTable;
                    this.DG_CustomerList.DataSource = CustomerDataTable;
                    this.DG_CustomerList.DataBind();
                    if (CheckCISCustomer())
                    {
                        this.Lb_CISWarning.Visible = true;
                    }
                    else
                    {
                        this.Lb_CISWarning.Visible = false;
                    }
                }
                else
                {
                    CustomerDataTable = new DataTable();
                    CustomerDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Title", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Company", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("NameCN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("TitleEN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("CompanyEN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Gender", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Remark", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("IsExisted", typeof(System.String)));
                    Session[SessionFlag.CustomerSession] = CustomerDataTable;
                    this.DG_CustomerList.DataSource = CustomerDataTable;
                    this.DG_CustomerList.DataBind();
                }

                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    this.tx_NumberOfPerson.Text = CustomerDataTable.Rows.Count.ToString();
                }
                else
                {
                    this.tx_NumberOfPerson.Text = "0";
                }
            }

            //ALCATEL ACCOMPANYING ATTENDEE INFO
            DataTable AlcatelAttendeeTable = null;
            object SessAlcatelAttendee = Session[SessionFlag.AccompanySession];
            if (SessAlcatelAttendee != null)
            {
                DG_AccompanyingStaff.DataSource = null;
                AlcatelAttendeeTable = (DataTable)SessAlcatelAttendee;
                this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                this.DG_AccompanyingStaff.DataBind();
            }
            else
            {
                if (this.App != null)
                {
                    AlcatelAttendeeTable = CRService.GetAccompanyingAttendeeList(this.App.Id);
                }
                if (AlcatelAttendeeTable != null && AlcatelAttendeeTable.Rows.Count > 0)
                {
                    Session[SessionFlag.AccompanySession] = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataBind();
                }
                else
                {
                    AlcatelAttendeeTable = new DataTable();
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("EmployeeId", typeof(System.String)));
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("ContactInfo", typeof(System.String)));
                    Session[SessionFlag.AccompanySession] = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataBind();
                }
            }

            //VISITING SITES
            if (this.App != null)
            {
                IList AppVisitingSites = CRService.GetVisitingSites(this.App.Id);
                if (AppVisitingSites != null && AppVisitingSites.Count > 0)
                {
                    BEGDC.CC.Entity.AppVisitingSite AppVS = null;
                    System.Web.UI.WebControls.ListItem item = null;
                    for (int i = 0; i < AppVisitingSites.Count; i++)
                    {
                        AppVS = (BEGDC.CC.Entity.AppVisitingSite)AppVisitingSites[i];
                        item = this.CBL_VisitingSites.Items.FindByValue(AppVS.Site.Id.ToString());
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }
            }


            //LOGISTICAL INFOMATION
            BEGDC.CC.Entity.LogisticalInfo LogisticalInfo = null;
            if (this.App != null)
            {
                LogisticalInfo = CRService.GetLogisticalInfo(this.App.Id);
            }
            if (LogisticalInfo != null)
            {
                this.Ctl_HotelComment.Text = LogisticalInfo.HotelComment;


                if (LogisticalInfo.MeetingRoom != null)
                {
                    this.Dp_MeetingRoom.SelectedIndex = Dp_MeetingRoom.Items.IndexOf(Dp_MeetingRoom.Items.FindByValue(LogisticalInfo.MeetingRoom.Id.ToString()));
                }
                this.checkbox1.Checked = LogisticalInfo.IsNormalBusiness;

                //Show Meeting Needs
                //if (this.Dp_MeetingRoom.SelectedItem.Text.Contains("Yes"))
                if (!string.IsNullOrEmpty(LogisticalInfo.MeetingNeeds))
                {
                    this.trMeetingNeeds.Visible = true;
                    //show the selected  meeting needs
                    foreach (ListItem item in this.cbMeetingNeeds.Items)
                    {
                        if (LogisticalInfo.MeetingNeeds.Contains(item.Text))
                            item.Selected = true;
                    }
                    //show other meeting needs
                    this.tbOtherMeetingNeeds.Text = LogisticalInfo.OtherMeetingNeeds;
                }

                if (LogisticalInfo.DateRequiredFrom != null && LogisticalInfo.DateRequiredFrom != "")
                {
                    this.Ctl_HotelDateFrom.Text = ((DateTime)LogisticalInfo.DateRequiredFrom).ToString("MM/dd/yyyy");
                }
                if (LogisticalInfo.DateRequiredTo != null && LogisticalInfo.DateRequiredTo != "")
                {
                    this.Ctl_HotelDateTo.Text = ((DateTime)LogisticalInfo.DateRequiredTo).ToString("MM/dd/yyyy");
                }
                InitRadioControl(this.RBL_Meal, LogisticalInfo.IsNeedCatering);
                this.Ctl_MealContent.Text = LogisticalInfo.CateringDescription;
                this.Ctl_LogisticComment.Text = LogisticalInfo.Comment;

                //Arrival Fight No
                this.Ctl_ArrivalFlightNo.Text = LogisticalInfo.ArrivalFlightNo;
                this.Ctl_ArrivalAirport.Text = LogisticalInfo.ArrivalAirport;
                if (LogisticalInfo.ArrivalTime != null && LogisticalInfo.ArrivalTime != "")
                {
                    this.ArrivalTime.Text = ((DateTime)LogisticalInfo.ArrivalTime).ToString("MM/dd/yyyy");
                }

                //Leave Fight No
                this.Ctl_LeaveFlightNo.Text = LogisticalInfo.DepartureFlightNo;
                this.Ctl_LeaveAirport.Text = LogisticalInfo.DepartureAirport;
                if (LogisticalInfo.DepartureTime != null && LogisticalInfo.DepartureTime != "")
                {
                    this.LeaveTime.Text = ((DateTime)LogisticalInfo.DepartureTime).ToString("MM/dd/yyyy");
                }
                this.Ctl_Routing.Text = LogisticalInfo.Itinerary;

                InitRadioControl(this.RBL_Entertainment, LogisticalInfo.IsNeedEntertainment);
                this.Ctl_EntertainmentContent.Text = LogisticalInfo.EntertainmentPreference;

                InitRadioControl(this.RBL_Gift, LogisticalInfo.IsNeedGift);
                this.Ctl_GiftContent.Text = LogisticalInfo.GiftDetails;
            }

            //HOTEL PREFERENCE
            //LOAD HOTEL LIST
            DataTable HotelDataTable = null;
            object SessHotelBooking = Session[SessionFlag.HotelSession];
            if (SessHotelBooking != null)
            {
                HotelDataTable = (DataTable)SessHotelBooking;
                this.DG_Hotel.DataSource = HotelDataTable;
                this.DG_Hotel.DataBind();
            }
            else
            {
                if (LogisticalInfo != null)
                {
                    HotelDataTable = CRService.GetHotelRoomBookingList(LogisticalInfo.Id, false);
                }
                if (HotelDataTable != null && HotelDataTable.Rows.Count > 0)
                {
                    Session[SessionFlag.HotelSession] = HotelDataTable;
                    this.DG_Hotel.DataSource = HotelDataTable;
                    this.DG_Hotel.DataBind();
                }
                else
                {
                    HotelDataTable = new DataTable();
                    HotelDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    HotelDataTable.Columns.Add(new DataColumn("HotelId", typeof(System.String)));
                    HotelDataTable.Columns.Add(new DataColumn("HotelName", typeof(System.String)));
                    HotelDataTable.Columns.Add(new DataColumn("RoomTypeId", typeof(System.String)));
                    HotelDataTable.Columns.Add(new DataColumn("RoomTypeName", typeof(System.String)));
                    HotelDataTable.Columns.Add(new DataColumn("RoomNumber", typeof(System.String)));
                    Session[SessionFlag.HotelSession] = HotelDataTable;
                    this.DG_Hotel.DataSource = HotelDataTable;
                    this.DG_Hotel.DataBind();
                }
            }

            //COMPANY CAR
            DataTable CompanyCarDataTable = null;
            object SessCompanyCarBooking = Session[SessionFlag.CompanyCarSession];
            if (SessCompanyCarBooking != null)
            {
                CompanyCarDataTable = (DataTable)SessCompanyCarBooking;
                this.DG_CompanyCar.DataSource = CompanyCarDataTable;
                this.DG_CompanyCar.DataBind();
            }
            else
            {
                if (LogisticalInfo != null)
                {
                    CompanyCarDataTable = CRService.GetVehicleBookingList(LogisticalInfo.Id, BEGDC.CC.BL.Common.DicType.AlcatelCar);
                }
                if (CompanyCarDataTable != null && CompanyCarDataTable.Rows.Count > 0)
                {
                    Session[SessionFlag.CompanyCarSession] = CompanyCarDataTable;
                    this.DG_CompanyCar.DataSource = CompanyCarDataTable;
                    this.DG_CompanyCar.DataBind();
                    //this.Lb_TotalPriceForCompanyCar.Text = CaculateTotalPriceForLeaseCar(CompanyCarDataTable);
                }
                else
                {
                    CompanyCarDataTable = new DataTable();
                    CompanyCarDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    CompanyCarDataTable.Columns.Add(new DataColumn("VehicleTypeId", typeof(System.String)));
                    CompanyCarDataTable.Columns.Add(new DataColumn("VehicleType", typeof(System.String)));
                    CompanyCarDataTable.Columns.Add(new DataColumn("VehicleNumber", typeof(System.String)));
                    CompanyCarDataTable.Columns.Add(new DataColumn("OtherVehicle", typeof(System.String)));
                    Session[SessionFlag.CompanyCarSession] = CompanyCarDataTable;
                    this.DG_CompanyCar.DataSource = CompanyCarDataTable;
                    this.DG_CompanyCar.DataBind();
                }
            }

            //LEASE CAR
            DataTable LeaseCarDataTable = null;
            object SessLeaseCarBooking = Session[SessionFlag.LeaseCarSession];
            if (SessLeaseCarBooking != null)
            {
                LeaseCarDataTable = (DataTable)SessLeaseCarBooking;
                this.DG_LeaseCar.DataSource = LeaseCarDataTable;
                this.DG_LeaseCar.DataBind();
            }
            else
            {
                if (LogisticalInfo != null)
                {
                    LeaseCarDataTable = CRService.GetVehicleBookingList(LogisticalInfo.Id, BEGDC.CC.BL.Common.DicType.LeaseCar);
                }
                if (LeaseCarDataTable != null && LeaseCarDataTable.Rows.Count > 0)
                {
                    Session[SessionFlag.LeaseCarSession] = LeaseCarDataTable;
                    this.DG_LeaseCar.DataSource = LeaseCarDataTable;
                    this.DG_LeaseCar.DataBind();
                    //this.Lb_TotalPriceForLeaseCar.Text = CaculateTotalPriceForLeaseCar(LeaseCarDataTable);
                }
                else
                {
                    LeaseCarDataTable = new DataTable();
                    LeaseCarDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    LeaseCarDataTable.Columns.Add(new DataColumn("VehicleTypeId", typeof(System.String)));
                    LeaseCarDataTable.Columns.Add(new DataColumn("VehicleType", typeof(System.String)));
                    LeaseCarDataTable.Columns.Add(new DataColumn("VehicleNumber", typeof(System.String)));
                    Session[SessionFlag.LeaseCarSession] = LeaseCarDataTable;
                    this.DG_LeaseCar.DataSource = LeaseCarDataTable;
                    this.DG_LeaseCar.DataBind();
                }
            }
        }

        private void InitRadioControl(System.Web.UI.WebControls.RadioButtonList Rbl, bool choice)
        {
            if (choice)
            {
                Rbl.Items.FindByValue("1").Selected = true;
                Rbl.Items.FindByValue("0").Selected = false;
            }
            else
            {
                Rbl.Items.FindByValue("1").Selected = false;
                Rbl.Items.FindByValue("0").Selected = true;
            }
        }

        private string CaculateTotalPriceForLeaseCar(DataTable dataTable)
        {
            ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
            double Total = 0;
            int VID = 0;
            int Quat = 0;
            double UnitPrice = 0;
            BEGDC.CC.Entity.VehicleType vehicle = null;
            if (dataTable == null || dataTable.Rows.Count == 0) return Total.ToString();
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                VID = Convert.ToInt32(dataTable.Rows[i]["VehicleTypeId"].ToString());
                vehicle = CRService.GetVehicleType(VID);
                UnitPrice = Convert.ToDouble(vehicle.Price);
                Quat = Convert.ToInt32(dataTable.Rows[i]["VehicleNumber"].ToString());
                Total += UnitPrice * Quat;
            }
            return Total.ToString();
        }
        #endregion

        #region Controls Display
        private void ControlsDisplay(bool isreadonly)
        {
            if (isreadonly)
            {
                // this.ddlLegalEntity.Visible = false;
                // this.Ctl_ApplicantName.Visible = false;
                //this.Ctl_Telephone.Visible = false;
                //this.Ctl_Cellphone.Visible = false;
                this.Ctl_Country.Visible = false;
                this.Ctl_Company.Visible = false;
                this.Ctl_ArrivalDate.Visible = false;
                this.Ctl_LeaveDate.Visible = false;
                this.CBL_VisitingSites.Enabled = false;

                this.Dp_MeetingRoom.Visible = false;
                this.cbMeetingNeeds.Visible = false;
                this.tbOtherMeetingNeeds.Visible = false;

                this.Ctl_HotelDateFrom.Visible = false;
                this.Ctl_HotelDateTo.Visible = false;
                this.Ctl_ArrivalFlightNo.Visible = false;
                this.Ctl_ArrivalAirport.Visible = false;
                this.ArrivalTime.Visible = false;
                this.Ctl_LeaveFlightNo.Visible = false;
                this.Ctl_LeaveAirport.Visible = false;
                this.LeaveTime.Visible = false;
                this.Ctl_LogisticComment.Visible = false;
                this.CustomerPaneImg.Visible = false;
                this.AccompanyingPaneImg.Visible = false;
                this.HotelBookingImg.Visible = false;
                this.CompanyCarImg.Visible = false;
                this.LeaseCarImg.Visible = false;
                this.RBL_Meal.Enabled = false;
                this.RBL_Entertainment.Enabled = false;
                this.RBL_Gift.Enabled = false;
                this.Ctl_MealContent.Visible = false;
                this.Ctl_EntertainmentContent.Visible = false;
                this.Ctl_GiftContent.Visible = false;
                this.ArrivalDateSpan.Visible = false;
                this.LeaveDateSpan.Visible = false;
                this.HotelDateFromSpan.Visible = false;
                this.HotelDateToSpan.Visible = false;
                this.ArrivalTimeSpan.Visible = false;
                this.LeaveTimeSpan.Visible = false;
                this.Dp_Department.Visible = false;
                this.Dp_Account.Visible = false;
                this.tbDp_Account.Visible = false;
                this.Ctl_Routing.Visible = false;
                this.Ctl_HotelComment.Visible = false;
            }
            else
            {
                //this.lblLegalEntity.Visible = false;
                //this.tx_Applicant.Visible = false;
                //this.tx_Telephone.Visible = false;
                //this.tx_Cellphone.Visible = false;
                this.tx_AllDepts.Visible = false;
                this.tx_Account.Visible = false;
                this.tx_Country.Visible = false;
                this.tx_Company.Visible = false;
                //this.tx_NumberOfPerson.Visible = false;
                this.Dt_ArrivalDate.Visible = false;
                this.Dt_LeaveDate.Visible = false;
                this.tx_MeetingRoom.Visible = false;
                this.lblOtherMeetingNeeds.Visible = false;
                this.lblMeetingNeeds.Visible = false;
                this.Dt_ArrivalDate.Visible = false;
                this.Dt_LeaveDate.Visible = false;
                this.tx_ArrivalFightNo.Visible = false;
                this.tx_ArrivalAirport.Visible = false;
                this.tx_ArrivalTime.Visible = false;
                this.tx_LeaveFightNo.Visible = false;
                this.tx_LeaveAirport.Visible = false;
                this.tx_LeaveTime.Visible = false;
                this.lbLogisticComment.Visible = false;
                this.Lb_Routing.Visible = false;
                //this.TR_Meal.Visible = false;
                //this.TR_Gifts.Visible = false;
                //this.TR_Enterainment.Visible = false;
            }
        }
        #endregion

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Dp_Department.SelectedIndexChanged += new System.EventHandler(this.CATBranch_SelectChange);
            this.DG_CustomerList.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.CustomerDeleteCommand);
            this.DG_CustomerList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.CustomerListDateBound);
            this.DG_AccompanyingStaff.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.ASBAttendeeDeleteCommand);
            this.DG_AccompanyingStaff.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.ASBAttendee_ItemDataBound);
            this.DG_Hotel.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.HotelList_DeleteCommand);
            this.DG_Hotel.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.HotelDataBound);
            this.DG_CompanyCar.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.CompanyCarDeleteCommand);
            this.DG_CompanyCar.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.AlcatelCarDataBound);
            this.DG_LeaseCar.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.LeaseCarDeleteCommand);
            this.DG_LeaseCar.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.LeaseCarDataBound);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        #region BuildObjects

        public BEGDC.CC.Entity.Application BuildApplication(BEGDC.CC.Entity.Application AppObj)
        {
            IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
            BEGDC.CC.Entity.Application App = AppObj;
            if (App == null)
            {
                App = new BEGDC.CC.Entity.Application();
            }

            IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
            IUtility utiService = AppContainer.Instance[ServiceConst.UtilityService] as IUtility;

            //App.RequesterNameEN = this.Ctl_ApplicantName.Text;
            //App.RequesterNameEN = this.RequesterInfoControl.Employee.NameEN;
            App.RequesterNameEN = this.RequesterInfoControl.NameEN;
            //App.RequesterOfficeTel = this.Ctl_Telephone.Text;
            //App.RequesterOfficeTel = this.RequesterInfoControl.Employee.OfficePhone;
            App.RequesterOfficeTel = this.RequesterInfoControl.OfficePhone;
            //App.RequesterMobile = this.Ctl_Cellphone.Text;
            //App.RequesterMobile = this.RequesterInfoControl.Employee.Mobile;
            App.RequesterMobile = this.RequesterInfoControl.Mobile;
            App.RequesterNo = userService.GetUser(App.RequesterNameEN);

            //Used CostCenterName to Save selected CostCenter
            //App.CostCenterCode = utiService.GetDicItem(Convert.ToInt32(this.Dp_CostCenter.SelectedValue));
            App.CostCenterName = this.Dp_CostCenter.SelectedValue;
            //Used OtherCountry to Save CostCenter Amount
            //App.OtherCountry = this.tbExpenditureAccount.Text;
            //Used ReasonOfLocation to Save CostCenter Remark
            //App.ReasonOfLocation = this.tbCostCenterRemarks.Text;

            if (this.Dp_Department.SelectedValue.ToString() == "" && this.tx_AllDepts.Text == "")
            {
                Page.RegisterClientScriptBlock("", "<script>alert('Please select a CAT or Branch. 请选择大客户或省份!');</script>");
                return null;
            }
            App.CATBranch = this.Dp_Department.SelectedValue.ToString();
            //Used Others to Save Cluster
            App.Others = this.lblCluster.Text;

            //Other Account
            //App.Account = this.Dp_Account.SelectedValue.ToString();
            if (this.Dp_Account.SelectedValue.ToString() == OtherAccounts && string.IsNullOrEmpty(this.tbDp_Account.Text.Trim()))
            {
                Page.RegisterClientScriptBlock("", "<script>alert('Other Account could not be empty. 其他大客户不能为空!');</script>");
                return null;
            }
            App.Account = (this.Dp_Account.SelectedValue.ToString() == OtherAccounts) ? this.tbDp_Account.Text.Trim() : this.Dp_Account.SelectedValue.ToString();

            App.RequestDate = this.RequestDate;
            //App.AllDept = this.Dp_Department.SelectedValue.ToString();
            BEGDC.CC.Entity.Department dept = null;
            if (!string.IsNullOrEmpty(this.lblCluster.Text))
            {
                string deptStr = string.IsNullOrEmpty(this.Dp_Department.SelectedValue.ToString()) ? this.tx_AllDepts.Text : this.Dp_Department.SelectedValue.ToString();
                dept = query.GetDepartmentByPCAT(deptStr, true);
            }
            else
            {
                string deptStr = string.IsNullOrEmpty(this.Dp_Department.SelectedValue.ToString()) ? this.tx_AllDepts.Text : this.Dp_Department.SelectedValue.ToString();
                dept = query.GetDepartmentByPCAT(deptStr, false);
            }

            if (dept == null)
            {
                Page.RegisterClientScriptBlock("", "<script>alert('No department in the PCAT. 该省份或大客户没有对应的部门!');</script>");
                return null;
            }
            else
            {
                App.AllDept = dept.DepartmentCode;
            }

            //BEGDC.CC.Entity.Department dept = query.GetDepartmentByCode(this.Dp_Department.SelectedValue.ToString());
            if ((dept != null && (dept.DepartmentType.DicItemKey == BEGDC.CC.BL.Common.SysDicItem.DepartmentType.CAT)) || (this.Dp_Department.SelectedValue.ToString() == "OTH"))
            {
                //App.AllDept  = "HQ"+this.Dp_Department.SelectedValue.ToString();
                App.Account = string.Empty;
            }

            string RequestDateFrom = this.Ctl_ArrivalDate.Text;
            if (RequestDateFrom != "")
            {
                App.RequestedDateFrom = Nullables.NullableDateTime.Parse(RequestDateFrom);
            }
            else
            {
                App.RequestedDateFrom = Nullables.NullableDateTime.Default;
            }
            string RequestDateTo = this.Ctl_LeaveDate.Text;
            if (RequestDateTo != "")
            {
                App.RequestedDateTo = Nullables.NullableDateTime.Parse(RequestDateTo);
            }
            else
            {
                App.RequestedDateTo = Nullables.NullableDateTime.Default;
            }
            //if (this.ddlLegalEntity.SelectedItem != null)
            //{
            //    App.LegalEntity = new LegalEntity();
            //    App.LegalEntity.Id = Convert.ToInt32(this.ddlLegalEntity.SelectedValue);
            //}

            return App;
        }

        public BEGDC.CC.Entity.CustomerInfo BuildCustomer(BEGDC.CC.Entity.Application AppObj)
        {
            ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
            BEGDC.CC.Entity.CustomerInfo customer = null;
            if (AppObj.Id <= 0)
            {
                customer = new BEGDC.CC.Entity.CustomerInfo();
            }
            else
            {
                customer = CRService.GetCustomerInfo(AppObj.Id);
                if (customer == null)
                {
                    customer = new BEGDC.CC.Entity.CustomerInfo();
                }
            }

            customer.Country = this.Ctl_Country.Text;
            customer.Company = this.Ctl_Company.Text;
            //customer.NumberOfPerson = this.Ctl_NumberOfPerson.Text;
            if (this.DG_CustomerList.Items.Count > 0)
            {
                customer.NumberOfPerson = this.DG_CustomerList.Items.Count.ToString();
            }

            string VenueInfo = string.Empty;
            int Count = this.CBL_VisitingSites.Items.Count;
            System.Web.UI.WebControls.ListItem item = null;
            for (int i = 0; i < Count; i++)
            {
                item = this.CBL_VisitingSites.Items[i] as ListItem;
                if (item.Selected)
                {
                    VenueInfo += (item.Text.IndexOf("<a") > -1 ? item.Text.Substring(0, item.Text.IndexOf("<a")) : item.Text) + ",";
                }
            }
            if (VenueInfo.Length > 0)
                VenueInfo = VenueInfo.TrimEnd(',');
            //VenueInfo = VenueInfo.Substring(0,100);
            customer.Venue = VenueInfo;
            return customer;
        }

        public BEGDC.CC.Entity.LogisticalInfo BuildLogistic(BEGDC.CC.Entity.Application AppObj)
        {
            ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
            BEGDC.CC.Entity.LogisticalInfo logistic = null;
            if (AppObj.Id <= 0)
            {
                logistic = new BEGDC.CC.Entity.LogisticalInfo();
            }
            else
            {
                logistic = CRService.GetLogisticalInfo(AppObj.Id);
                if (logistic == null)
                {
                    logistic = new BEGDC.CC.Entity.LogisticalInfo();
                }
            }

            //Meeting Room
            IUtility utiService = AppContainer.Instance[ServiceConst.UtilityService] as IUtility;
            logistic.MeetingRoom = utiService.GetDicItem(Convert.ToInt32(this.Dp_MeetingRoom.SelectedItem.Value));

            //Save Meeting Needs
            //if (this.Dp_MeetingRoom.SelectedItem.Text.Contains("Yes"))
            if (this.CBL_VisitingSites.SelectedValue == "683")
            {
                string meetingNeedsStr = string.Empty;
                foreach (ListItem item in this.cbMeetingNeeds.Items)
                {
                    if (item.Selected)
                    {
                        meetingNeedsStr += item.Value.ToString() + ",";
                    }
                }
                logistic.MeetingNeeds = string.IsNullOrEmpty(meetingNeedsStr) ? string.Empty : meetingNeedsStr.Substring(0, meetingNeedsStr.Length - 1);
                logistic.OtherMeetingNeeds = this.tbOtherMeetingNeeds.Text.Trim();
            }

            //Hotel Info
            logistic.HotelComment = this.Ctl_HotelComment.Text;
            string HotelDateFrom = this.Ctl_HotelDateFrom.Text;
            if (HotelDateFrom != "")
            {
                logistic.DateRequiredFrom = Nullables.NullableDateTime.Parse(HotelDateFrom);
            }
            string HotelDateTo = this.Ctl_HotelDateTo.Text;
            if (HotelDateTo != "")
            {
                logistic.DateRequiredTo = Nullables.NullableDateTime.Parse(HotelDateTo);
            }

            //MEAL RESERVATION
            logistic.IsNeedCatering = GetValueRadioControl(this.RBL_Meal);
            logistic.CateringDescription = this.Ctl_MealContent.Text;

            // Flight Info
            logistic.ArrivalFlightNo = this.Ctl_ArrivalFlightNo.Text;
            logistic.DepartureFlightNo = this.Ctl_LeaveFlightNo.Text;

            logistic.ArrivalAirport = this.Ctl_ArrivalAirport.Text;
            logistic.DepartureAirport = this.Ctl_LeaveAirport.Text;

            string ArrivalTime = this.ArrivalTime.Text;
            if (ArrivalTime != "")
            {
                logistic.ArrivalTime = Nullables.NullableDateTime.Parse(ArrivalTime);
            }
            string DepartureTime = this.LeaveTime.Text;
            if (DepartureTime != "")
            {
                logistic.DepartureTime = Nullables.NullableDateTime.Parse(DepartureTime);
            }
            logistic.IsNormalBusiness = this.checkbox1.Checked;
            //ENTERTAINMENT & GIFTS
            logistic.IsNeedEntertainment = GetValueRadioControl(this.RBL_Entertainment);
            logistic.EntertainmentPreference = this.Ctl_EntertainmentContent.Text;
            logistic.IsNeedGift = GetValueRadioControl(this.RBL_Gift);
            logistic.GiftDetails = this.Ctl_GiftContent.Text;
            logistic.Itinerary = this.Ctl_Routing.Text;
            logistic.Comment = this.Ctl_LogisticComment.Text;

            return logistic;
        }


        public IList BuildAppVisiting()
        {
            IList SelectedList = new ArrayList();
            int Count = this.CBL_VisitingSites.Items.Count;
            System.Web.UI.WebControls.ListItem item = null;
            for (int i = 0; i < Count; i++)
            {
                item = this.CBL_VisitingSites.Items[i] as ListItem;
                if (item.Selected)
                {
                    SelectedList.Add(item.Value.ToString());
                }
            }
            return SelectedList;
        }

        private bool GetValueRadioControl(System.Web.UI.WebControls.RadioButtonList Rbl)
        {
            if (Rbl.Items[0].Selected)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region DataGrid DataBound
        private void CustomerListDateBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                string Gender = e.Item.Cells[4].Text.ToString();
                if (Gender == "True")
                {
                    e.Item.Cells[5].Text = "Male";
                }
                else
                {
                    e.Item.Cells[5].Text = "Female";
                }

                //Init Edit Button
                System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton)e.Item.Cells[9].FindControl("Btn_Customer_Edit");
                //string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenCustomerPane(" + e.Item.ItemIndex + ",'Edit');");
                Btn_Edit.Attributes.Add("check", "false");


                //Init Warning Sign
                string IsExisted = e.Item.Cells[7].Text.ToString();
                if (IsExisted == BEGDC.CC.BL.Common.CISFlag.NotExisted)
                {
                    System.Web.UI.WebControls.Image WarningImg = (System.Web.UI.WebControls.Image)e.Item.Cells[8].FindControl("CISWarning");
                    WarningImg.Visible = true;
                    WarningImg.ImageUrl = "../../images/Warning.gif";
                    WarningImg.ToolTip = "The Customer is not in CIS (该客户不是CIS成员)";
                }
                if (IsExisted == BEGDC.CC.BL.Common.CISFlag.Existed)
                {
                    System.Web.UI.WebControls.Image WarningImg = (System.Web.UI.WebControls.Image)e.Item.Cells[8].FindControl("CISWarning");
                    WarningImg.ImageUrl = "../../images/GreenWarningImg.gif";
                    WarningImg.ToolTip = "The Customer is in CIS (该客户是CIS成员)";
                    WarningImg.Visible = true;
                }

                ImageButton ld = (ImageButton)e.Item.Cells[9].FindControl("Btn_CustomerDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }
            }
        }

        private void CustomerDeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = e.Item.ItemIndex;

                DataTable CustomerDataTable = (DataTable)Session[SessionFlag.CustomerSession];
                DataRow CustomerRow = CustomerDataTable.Rows[rowid];
                CustomerDataTable.Rows.Remove(CustomerRow);

                Session[SessionFlag.CustomerSession] = CustomerDataTable;
                object SessCustomerBooking = Session[SessionFlag.CustomerSession];
                if (SessCustomerBooking != null)
                {
                    CustomerDataTable = (DataTable)SessCustomerBooking;
                    this.DG_CustomerList.DataSource = CustomerDataTable;
                    this.DG_CustomerList.DataBind();
                }
                if (CheckCISCustomer())
                {
                    this.Lb_CISWarning.Visible = true;
                }
                else
                {
                    this.Lb_CISWarning.Visible = false;
                }
            }
            catch
            {
            }
        }

        private void ASBAttendee_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton)e.Item.Cells[4].FindControl("Btn_Accompany_Edit");
                //string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenAccompanyingPane(" + e.Item.ItemIndex + ",'Edit');");
                Btn_Edit.Attributes.Add("check", "false");

                ImageButton ld = (ImageButton)e.Item.Cells[4].FindControl("Btn_AccompanyDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }
            }
        }

        private void ASBAttendeeDeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = e.Item.ItemIndex;

                DataTable AccompanyDataTable = (DataTable)Session[SessionFlag.AccompanySession];
                DataRow AccompanyRow = AccompanyDataTable.Rows[rowid];
                AccompanyDataTable.Rows.Remove(AccompanyRow);

                Session[SessionFlag.AccompanySession] = AccompanyDataTable;
                object SessAccompanyBooking = Session[SessionFlag.AccompanySession];
                if (SessAccompanyBooking != null)
                {
                    AccompanyDataTable = (DataTable)SessAccompanyBooking;
                    this.DG_AccompanyingStaff.DataSource = AccompanyDataTable;
                    this.DG_AccompanyingStaff.DataBind();
                }
            }
            catch
            {
            }
        }

        private void AlcatelCarDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton)e.Item.Cells[4].FindControl("Btn_AlcatelCar_Edit");
                //string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenCompanyCarPane(" + e.Item.ItemIndex + ",'Edit');");
                Btn_Edit.Attributes.Add("check", "false");

                ImageButton ld = (ImageButton)e.Item.Cells[4].FindControl("Btn_CompanyCarDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }

                if (e.Item.Cells[2].Text == "其他" || e.Item.Cells[2].Text == "其它" || e.Item.Cells[2].Text.Contains("Other"))
                {
                    e.Item.Cells[2].Text = e.Item.Cells[5].Text + "(其它)";
                }
            }
        }

        private void CompanyCarDeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = e.Item.ItemIndex;

                DataTable CompanyCarDataTable = (DataTable)Session[SessionFlag.CompanyCarSession];
                DataRow CompanyCarRow = CompanyCarDataTable.Rows[rowid];
                CompanyCarDataTable.Rows.Remove(CompanyCarRow);

                Session[SessionFlag.CompanyCarSessionEZ] = CompanyCarDataTable;
                object SessCompanyBooking = Session[SessionFlag.CompanyCarSession];
                if (SessCompanyBooking != null)
                {
                    CompanyCarDataTable = (DataTable)SessCompanyBooking;
                    this.DG_CompanyCar.DataSource = CompanyCarDataTable;
                    this.DG_CompanyCar.DataBind();
                }
            }
            catch
            {
            }
        }

        private void LeaseCarDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton)e.Item.Cells[4].FindControl("Btn_LeaseCar_Edit");
                //string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenLeaseCarPane(" + e.Item.ItemIndex + ",'Edit');");
                Btn_Edit.Attributes.Add("check", "false");

                ImageButton ld = (ImageButton)e.Item.Cells[4].FindControl("Btn_LeaseCarDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }
            }
        }

        private void LeaseCarDeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = e.Item.ItemIndex;

                DataTable LeaseCarDataTable = (DataTable)Session[SessionFlag.LeaseCarSession];
                DataRow LeaseCarRow = LeaseCarDataTable.Rows[rowid];
                LeaseCarDataTable.Rows.Remove(LeaseCarRow);

                Session[SessionFlag.LeaseCarSession] = LeaseCarDataTable;
                object SessLeaseBooking = Session[SessionFlag.LeaseCarSession];
                if (SessLeaseBooking != null)
                {
                    LeaseCarDataTable = (DataTable)SessLeaseBooking;
                    this.DG_LeaseCar.DataSource = LeaseCarDataTable;
                    this.DG_LeaseCar.DataBind();
                }
            }
            catch
            {
            }
        }

        private void HotelDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton)e.Item.Cells[6].FindControl("Btn_Hotel_Edit");
                //string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenHotelBookingPane(" + e.Item.ItemIndex + ",'Edit');");
                Btn_Edit.Attributes.Add("check", "false");

                ImageButton ld = (ImageButton)e.Item.Cells[4].FindControl("Btn_HotelDelete");
                if (ld != null)
                {
                    ld.Attributes.Add("onclick", "On_Submit();");
                    ld.Attributes.Add("check", "false");
                }
            }
        }

        private void HotelList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                if (Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
                {
                    return;
                }

                int rowid = e.Item.ItemIndex;

                DataTable HotelDataTable = (DataTable)Session[SessionFlag.HotelSession];
                DataRow HotelRow = HotelDataTable.Rows[rowid];
                HotelDataTable.Rows.Remove(HotelRow);

                Session[SessionFlag.HotelSessionEZ] = HotelDataTable;
                object SessHotelBooking = Session[SessionFlag.HotelSession];
                if (SessHotelBooking != null)
                {
                    HotelDataTable = (DataTable)SessHotelBooking;
                    this.DG_Hotel.DataSource = HotelDataTable;
                    this.DG_Hotel.DataBind();
                }
            }
            catch
            {
            }
        }
        #endregion

        #region Radio Box Select Change
        //		private void MealSelectChange(object sender, System.EventArgs e)
        //		{
        //			if(this.RBL_Meal.SelectedValue=="1")
        //			{
        //				this.TR_Meal.Visible = true;
        //			}
        //			else
        //			{
        //				this.TR_Meal.Visible = false;
        //			}
        //		}
        //		private void EnterainmentSelectChange(object sender, System.EventArgs e)
        //		{
        //			if(this.RBL_Entertainment.SelectedValue=="1")
        //			{
        //				this.TR_Enterainment.Visible = true;
        //			}
        //			else
        //			{
        //				this.TR_Enterainment.Visible = false;
        //			}
        //		}
        //		private void GiftsSelectChange(object sender, System.EventArgs e)
        //		{
        //			if(this.RBL_Gift.SelectedValue=="1")
        //			{
        //				this.TR_Gifts.Visible = true;
        //			}
        //			else
        //			{
        //				this.TR_Gifts.Visible = false;
        //			}
        //		}
        #endregion

        #region CheckCustomer
        private bool CheckCISCustomer()
        {
            if (this.DG_CustomerList.Items.Count == 0) return false;
            foreach (DataGridItem row in this.DG_CustomerList.Items)
            {
                string IsExisted = row.Cells[8].Text.ToString();
                if (IsExisted == BEGDC.CC.BL.Common.CISFlag.NotExisted)
                {
                    return true;
                }
            }
            return false;
        }
        #endregion

        #region CATBranch_SelectChange
        private void CATBranch_SelectChange(object sender, System.EventArgs e)
        {
            //æ¸…ç©ºæˆæœ¬ä¸­å¿ƒåˆ—è¡¨
            Dp_CostCenter.Items.Clear();

            if (string.IsNullOrEmpty(this.Dp_Department.SelectedValue))
            {
                this.lblCluster.Text = string.Empty;
            }
            else
            {
                IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                BEGDC.CC.Entity.Department dept = null;

                this.lblCluster.Text = query.GetClusterByProvinceName(this.Dp_Department.SelectedValue);
                if (!string.IsNullOrEmpty(this.lblCluster.Text))
                {
                    dept = query.GetDepartmentByPCAT(this.Dp_Department.SelectedValue, true);
                }
                else
                {
                    dept = query.GetDepartmentByPCAT(this.Dp_Department.SelectedValue, false);
                }
                if (dept == null)
                {
                    Page.RegisterClientScriptBlock("", "<script>alert('No department in the PCAT.该省份或大客户没有对应的部门!');</script>");
                    //this.lblCluster.CssClass = "";
                    return;
                }

                //BEGDC.CC.Entity.Department dept = query.GetDepartmentByCode(this.Dp_Department.SelectedValue);
                if ((dept != null && (dept.DepartmentType.DicItemKey == BEGDC.CC.BL.Common.SysDicItem.DepartmentType.CAT)) || (this.Dp_Department.SelectedValue.ToString() == "OTH"))
                {
                    this.TR_Account.Visible = false;
                }
                else
                {
                    //this.lblCluster.CssClass = "Cluster_Block";
                    this.TR_Account.Visible = true;
                }

                //Binding CostCenters
                this.BindCostCenterList();
            }
        }
        #endregion

        #region

        private void BindCostCenterList()
        {
            if (!string.IsNullOrEmpty(this.Dp_Department.SelectedValue))
            {
                IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                DataTable table = null;

                if (!string.IsNullOrEmpty(this.lblCluster.Text))
                {
                    //CostCenters in the Province 
                    table = query.GetCostCenterListByPCAT(this.Dp_Department.SelectedValue, true);
                }
                else
                {
                    //CostCenters in Category
                    table = query.GetCostCenterListByPCAT(this.Dp_Department.SelectedValue, false);
                }

                if (table.Rows.Count > 0)
                {
                    this.Dp_CostCenter.DataSource = table.DefaultView;
                    this.Dp_CostCenter.DataTextField = "CostCenterID";
                    this.Dp_CostCenter.DataValueField = "CostCenterID";
                    this.Dp_CostCenter.DataBind();
                    this.Dp_CostCenter.Enabled = true;
                    //this.tbExpenditureAccount.Enabled = true;
                    //this.tbCostCenterRemarks.Enabled = true;
                }
                else
                {
                    this.Dp_CostCenter.Enabled = false;
                    //this.tbExpenditureAccount.Enabled = false;
                    //his.tbCostCenterRemarks.Enabled = false;
                }
            }
        }
        #endregion

        #region DisableCATBranchAcount
        public void DisableCATBranchAcount()
        {
            this.Dp_Department.Enabled = false;
            this.Dp_Account.Enabled = false;
            if (this.tbDp_Account.Visible)
                this.tbDp_Account.Enabled = false;
        }
        #endregion

        #region Modify
        public void ShowNormalModifyStatus(int AppId)
        {
            BindNormalCustomerAttendee(AppId);
            BindNormalALAttendee(AppId);

            this.CustomerPaneImg.Visible = true;
            this.AccompanyingPaneImg.Visible = true;
            this.Ctl_ArrivalDate.Visible = true;
            this.Ctl_LeaveDate.Visible = true;
            this.ArrivalDateSpan.Visible = true;
            this.LeaveDateSpan.Visible = true;

            this.Ctl_ArrivalDate.Text = this.Dt_ArrivalDate.Text;
            this.Ctl_LeaveDate.Text = this.Dt_LeaveDate.Text;

            this.Dt_ArrivalDate.Visible = false;
            this.Dt_LeaveDate.Visible = false;

            this.DG_CustomerList.Columns[9].Visible = true;
            this.DG_AccompanyingStaff.Columns[4].Visible = true;
        }

        public void EndNormalModifyStatus()
        {
            Session[SessionFlag.CustomerSession] = null;
            Session[SessionFlag.AccompanySession] = null;

            this.AccompanyingPaneImg.Visible = false;
            this.CustomerPaneImg.Visible = false;
            this.Ctl_ArrivalDate.Visible = false;
            this.Ctl_LeaveDate.Visible = false;
            this.ArrivalDateSpan.Visible = false;
            this.LeaveDateSpan.Visible = false;
            this.Dt_ArrivalDate.Visible = true;
            this.Dt_LeaveDate.Visible = true;

            this.Dt_ArrivalDate.Text = this.Ctl_ArrivalDate.Text;
            this.Dt_LeaveDate.Text = this.Ctl_LeaveDate.Text;

            this.DG_CustomerList.Columns[9].Visible = false;
            this.DG_AccompanyingStaff.Columns[4].Visible = false;
        }
        private void BindNormalCustomerAttendee(int AppId)
        {
            //Customer Attendee
            //Load Customer Attendee List
            ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;

            DataTable CustomerDataTable = null;
            object SessCustomerAttendee = Session[SessionFlag.CustomerSession];
            if (SessCustomerAttendee != null)
            {
                DG_CustomerList.DataSource = null;
                CustomerDataTable = (DataTable)SessCustomerAttendee;
                this.DG_CustomerList.DataSource = CustomerDataTable;
                this.DG_CustomerList.DataBind();
            }
            else
            {
                Entity.CustomerInfo customer = CRService.GetCustomerInfo(AppId);
                if (customer != null)
                {
                    CustomerDataTable = CRService.GetCustomerAttendeeList(customer.Id);
                }
                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    Session[SessionFlag.CustomerSession] = CustomerDataTable;
                    this.DG_CustomerList.DataSource = CustomerDataTable;
                    this.DG_CustomerList.DataBind();
                    if (CheckCISCustomer())
                    {
                        this.Lb_CISWarning.Visible = true;
                    }
                    else
                    {
                        this.Lb_CISWarning.Visible = false;
                    }
                }
                else
                {
                    CustomerDataTable = new DataTable();
                    CustomerDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Title", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Company", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("NameCN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("TitleEN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("CompanyEN", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Gender", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("Remark", typeof(System.String)));
                    CustomerDataTable.Columns.Add(new DataColumn("IsExisted", typeof(System.String)));
                    Session[SessionFlag.CustomerSession] = CustomerDataTable;
                }
                if (CustomerDataTable != null && CustomerDataTable.Rows.Count > 0)
                {
                    this.tx_NumberOfPerson.Text = CustomerDataTable.Rows.Count.ToString();
                }
                else
                {
                    this.tx_NumberOfPerson.Text = "0";
                }
            }
        }
        private void BindNormalALAttendee(int AppId)
        {
            ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
            //ALCATEL ACCOMPANYING ATTENDEE INFO
            DataTable AlcatelAttendeeTable = null;
            object SessAlcatelAttendee = Session[SessionFlag.AccompanySession];
            if (SessAlcatelAttendee != null)
            {
                DG_AccompanyingStaff.DataSource = null;
                AlcatelAttendeeTable = (DataTable)SessAlcatelAttendee;
                this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                this.DG_AccompanyingStaff.DataBind();
            }
            else
            {
                this.App = CRService.GetApplication(AppId);
                if (this.App != null)
                {
                    AlcatelAttendeeTable = CRService.GetAccompanyingAttendeeList(AppId);
                }
                if (AlcatelAttendeeTable != null && AlcatelAttendeeTable.Rows.Count > 0)
                {
                    Session[SessionFlag.AccompanySession] = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataBind();
                }
                else
                {
                    AlcatelAttendeeTable = new DataTable();
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("EmployeeId", typeof(System.String)));
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
                    AlcatelAttendeeTable.Columns.Add(new DataColumn("ContactInfo", typeof(System.String)));
                    Session[SessionFlag.AccompanySession] = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataSource = AlcatelAttendeeTable;
                    this.DG_AccompanyingStaff.DataBind();
                }
            }
        }
        #endregion

        /// <summary>
        /// Set the selected ASB Leaders
        /// </summary>
        private void SetSelectedASBLeaders()
        {
            //Bind CBL_ASBLeader
            //BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
            //IList list = utility.BuildCheckBoxASBLeaders();

            //CBL_ASBLeader.DataSource = list;
            //CBL_ASBLeader.DataValueField = "ID";
            //CBL_ASBLeader.DataTextField = "NameCN";
            //CBL_ASBLeader.DataBind();

            //// Set the selected ASB Leaders
            //if (this.App != null)
            //{
            //    IList appASBLeadersList = utility.AppASBLeadersList(this.App.Id);

            //    if (appASBLeadersList != null && appASBLeadersList.Count > 0)
            //    {
            //        System.Web.UI.WebControls.ListItem item = null;
            //        for (int i = 0; i < appASBLeadersList.Count; i++)
            //        {
            //            ASBCC.Database.EntityFramework.AppASBSenoirLeaders asbLeaders = appASBLeadersList[i] as ASBCC.Database.EntityFramework.AppASBSenoirLeaders;

            //            if (asbLeaders.ASBSeniorLeaders == null) continue;

            //            item = this.CBL_ASBLeader.Items.FindByValue(asbLeaders.ASBSeniorLeaders.ID.ToString());

            //            if (item != null)
            //            {
            //                item.Selected = true;
            //            }
            //        }
            //    }
            //}

            BEGDC.CC.BL.Common.Query.IQuery query = AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;
            //DataTable table = query.GetAppASBLeadersList(this.App.Id);
            //CBL_ASBLeader.DataSource = table;
            //CBL_ASBLeader.DataValueField = "DicItemID";
            //CBL_ASBLeader.DataTextField = "DicItemKey";
            //CBL_ASBLeader.DataBind();

            DataTable table2 = query.GetAppASBLeadersList2(this.App.Id);
            this.dgASBLeaders.DataSource = table2;
            this.dgASBLeaders.DataBind();
        }
    }
}
